package com.aitaoxue.palx.service;

import java.util.ArrayList;
import java.util.List;

import android.app.IntentService;
import android.content.Intent;

import com.aitaoxue.palx.bean.Course;
import com.aitaoxue.palx.bean.CourseList;
import com.aitaoxue.palx.db.course.CourseContext;

//保存获得的订单
public class CourseService extends IntentService {

	private static final String TAG = CourseService.class.getSimpleName();

	public CourseService() {
		super("courseService");
	}

	private List<Callback> listenerList;

	public void setCallback(Callback callback) {
		if (listenerList == null) {
			listenerList = new ArrayList<Callback>();
		}
		
		if (!listenerList.contains(callback)) {
			listenerList.add(callback);
		}
	}

	@Override
	protected void onHandleIntent(Intent intent) {
//		CourseList list = (CourseList) intent.getSerializableExtra("courses");
//		List<Course> courseList = list.getList();
//		String type = intent.getStringExtra("type");
//
//		List<String> tmp = new ArrayList<String>();
//
//		for (Course course : courseList) {
//			// Log.d(TAG, "show:"+course.getOrder_id());
//			// 不存在
//			if (!CourseContext.getInstance().Exist(course.getOrder_id())) {
//				CourseContext.getInstance().saveEntity(course, type, 1, null);
//				// Log.d(TAG, "save"+course.getOrder_id());
//
//				tmp.add(course.getOrder_id());
//			}
//		}
//
//		// 保存结束,通知ui改变
//		for (Callback callback : listenerList) {
//			callback.onFinished(tmp);
//		}
	}

	public interface Callback {
		void onFinished(List<String> list);
	}

}
